<template>
  <dw-tree ref="teamTreeRef" :getTreeUrl="getTreeUrl" :addTreeUrl="addTreeUrl" :editTreeUrl="editTreeUrl" :delTreeUrl="delTreeUrl" :treeProps="treeProps" @currentChange="currentNodeChange"></dw-tree>
</template>
<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
import type { ITeam } from '../../team/team.d';
defineOptions({
  name: 'UserTeamTree',
});
const teamTreeRef = ref();
const getTreeUrl: string = '/admin-api/sys/team/with/producer/list';
const addTreeUrl: string = '/admin-api/sys/team';
const editTreeUrl: string = '/admin-api/sys/team';
const delTreeUrl: string = '/admin-api/sys/team/{id}';
const treeProps = { label: 'teamName', children: 'children' };
const currentNodeData = ref<ITeam | undefined>();
const emits = defineEmits(['currentNodeChange']);
const currentNodeChange = (data: ITeam) => {
  currentNodeData.value = data;
};
onMounted(() => {
  teamTreeRef.value.setCurrentKey('0d000863-a9bb-4ac5-b638-41db60969aa5', true);
  setTimeout(() => {
    currentNodeData.value = teamTreeRef.value.getCurrentNode();
  }, 200);
});
watch(currentNodeData, () => {
  emits('currentNodeChange', currentNodeData.value);
});
</script>
